package ph.com.gs3.formalistics.model.dao;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class SQLiteDataAccessObject extends DataAccessObject {

	public static final String TAG = SQLiteDataAccessObject.class.getSimpleName();

	// Database Fields
	protected SQLiteDatabase database;
	protected FLDatabaseHelper databaseHelper;

	public SQLiteDataAccessObject(FLDatabaseHelper databaseHelper) {
		super(databaseHelper.getContext());
		this.databaseHelper = databaseHelper;
	}

	public SQLiteDataAccessObject(Context context) {
		super(context);
		databaseHelper = new FLDatabaseHelper(context);
	}

	public void open() throws SQLException {
		database = databaseHelper.getWritableDatabase();
	}

	public void close() {
		databaseHelper.close();
	}

	// ========================================================================
	// Exceptions

	public static class DAOClosedException extends Exception {
		private static final long serialVersionUID = -2040640986487604192L;

		public DAOClosedException() {
			super("Attempt to use a DAO without opening it.");
		}

	}
}
